<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LoginController extends Controller
{

	public function index (  )
	{
		return view('login.index');
	}


	/**
	 * 登录动作
	 */
	public function login ( Request $request )
	{
		$this->validate($request ,[
				'email' => 'required',
				'password' => 'required',
		]);

		$isRemember = boolval(request('is_remember'));

//		$param = array_merge(request(['email']))

		if(\Auth::attempt(request(['email','password']),$isRemember)){
			return redirect('/post/index');
		}

		return redirect()->back()->withErrors('用户名密码错误');

	}

	public function logout (  )
	{
		\Auth::logout();
		return redirect('login/index');
	}
}
